GBML manual / Language

The order of a frame

The exact sequence every frame runs in, from Step Begin to the frame being shown.

Why the order matters

Two events can both be true "every frame" and still need to run in a specific order relative to each other - movement has to happen before collisions are checked against the new position, and drawing has to happen after every instance has finished moving for the frame, or things would visibly lag a step behind where they actually are. GBML fixes this order once, for every object, so you never have to reason about which of two objects' Step events happens to run first.

The ten steps

The ten steps of a frame, in order, looping back to the first for the next frameThe ten steps of a frame, in order, looping back to the first for the next frame
The ten steps of a frame, in order, looping back to the first for the next frame
  1. Step Begin
  2. Alarms
  3. Button events
  4. Step
  5. Movement - friction, then gravity, then speed/direction are applied, then paths are followed
  6. Beyond Room / Hit Room Edge / Beyond View / Inside View - checked against the position movement just produced
  7. Collisions - every overlap for this frame is found first, then every Collision event for this frame runs (Events covers why that order specifically matters)
  8. Step End
  9. Draw Begin → Draw → Draw End → Draw GUI
  10. The finished frame is shown, and then the end-of-frame clean-up runs: every instance that instance_destroy() was called on this frame gets its Destroy event, then Cleanup, and is removed, per Objects and instances. The instance finished the frame first: Destroy is never run in the middle of the frame

Then the whole sequence repeats for the next frame.

Where movement fits

Step 5 is why you set speed/direction (or hsp/vsp) during Step rather than computing a new position by hand: whatever you set during Step 3/4 gets applied automatically at step 5, in one consistent place, before collisions are checked against the result. Reading x/ y during Step still gives you this frame's starting position - movement has not run yet.

Entering a room

Room entry does not skip or reorder any of the above; it just has its own boundary once, before the first ordinary frame in the room begins:

  1. For each instance placed in the room, in the order the room lists them: its object's own settings (sprite, Visible, Solid...) go on it, its Create event runs, then its own creation code (if any) runs. One instance finishes before the next is made.
  2. Game Start runs, but only when this is the very first room of the game.
  3. The room's own creation code runs.
  4. Room Start runs for every instance now in the room.

Only after all of that does the room's first ordinary frame begin at step 1 above. When each event runs draws this order as a picture.

See also: EventsObjects and instancesBudgets